package com.shihb.structuralpatterns.decoratorpattern;/**
 *Description:装饰者和具体的装饰者
 *Version:1.0.0
 *@author shihb
 *@date 2020/7/18 21:29
 */
public class Decorator extends  Drink {
  private Drink drink;

  public Decorator(Drink drink) {
    this.drink = drink;
  }
  @Override
  public void setDes(String des) {
    super.setDes(drink.getDes()+"----"+drink.cost()+"\n  "+ des+"----"+ getPrice());
  }

  @Override
  Double cost() {
    return getPrice()+drink.cost();
  }
}

class  Milk extends Decorator{

  public Milk(Drink drink) {
    super(drink);
    setPrice(3.0D);
    setDes("牛奶");
  }
}
class  Chocolate extends Decorator{

  public Chocolate(Drink drink) {
    super(drink);
    setPrice(5.0D);
    setDes("巧克力");
  }
}
class  Cream extends Decorator{

  public Cream(Drink drink) {
    super(drink);
    setPrice(4.0D);
    setDes("奶盖");
  }
}

class  Sugar extends Decorator{

  public Sugar(Drink drink) {
    super(drink);
    setPrice(1.0D);
    setDes("糖");
  }
}
